package com.atos.smp.actions;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import org.primefaces.component.confirmdialog.ConfirmDialog;
import org.primefaces.component.dialog.Dialog;
import org.primefaces.component.inputtext.InputText;

import net.codeissue.web.common.ServiceFinder;

import com.atos.smp.beans.Collaborator;
import com.atos.smp.business.CollaboratorManager;
import com.atos.smp.business.impl.CollaboratorManagerImpl;
import com.atos.smp.dao.CollaboratorDao;

@ManagedBean
@SessionScoped
public class CollaboratorsBean implements Serializable {

	private CollaboratorManager collaboratorManager;
	private List<Collaborator> collaborators;
	private Collaborator selectedCollaborator;
	private Collaborator newCollaborator;
	private String das;
	private boolean update= false;

	public CollaboratorsBean() {
		collaboratorManager = Action.getCollaboratorManager();
		collaborators = collaboratorManager.findAllCollaborators();
		newCollaborator = new Collaborator();
		selectedCollaborator = new Collaborator();
	}

	public List<Collaborator> getCollaborators() {
		if(update)
			collaborators = collaboratorManager.findAllCollaborators();
		update = false;
		return collaborators;
	}

	public void setCollaborators(List<Collaborator> collaborators) {
		this.collaborators = collaborators;
	}

	public Collaborator getSelectedCollaborator() {
		return selectedCollaborator;
	}

	public void setSelectedCollaborator(Collaborator selectedCollaborator) {
		this.selectedCollaborator = selectedCollaborator;

	}

	public String addCollaborator() {
		collaboratorManager.save(newCollaborator);
		newCollaborator = new Collaborator();
		update = true;
		return "";
	}
	public String updateCollaborator() {
		collaboratorManager.update(selectedCollaborator);
		update = true;
		return "updateSuccess";
	}

	public void deleteCollaborator(Collaborator item) {
		if (item != null) {
			collaboratorManager.delete(item);
		}
		update=true;
	}

	public String getDas() {
		return das;
	}

	public void setDas(String das) {
		this.das = das;
		this.selectedCollaborator = collaboratorManager.findCollaboratorByDas(das);
	}
	public List<Collaborator> getManagers(){
		return collaboratorManager.findAllManagers();
	}
	public List<Collaborator> getProjectManagers(){
		return collaboratorManager.findAllProjectManagers();
	}

	public Collaborator getNewCollaborator() {
		return newCollaborator;
	}

	public void setNewCollaborator(Collaborator newCollaborator) {
		this.newCollaborator = newCollaborator;
	}

	public boolean isUpdate() {
		return update;
	}

	public void setUpdate(boolean update) {
		this.update = update;
	}
	
}
